package com.jshx.sz.gdjt.activity.listener;

import com.jshx.sz.gdjt.activity.TaskCheckActivity;
import com.jshx.sz.gdjt.client.ClientApplication;

import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.Toast;

public class MyTextWatcher implements   TextWatcher {

	 private String min;
	 private String max;
	 private EditText edit;
	 
	 public MyTextWatcher(EditText edit)
	 {
		this.edit=edit;
		this.max="1000";
	 }

	 public MyTextWatcher(String min,String max)
	 {
		 this.min=min;
		 this.max=max;
	 }
	 
	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub
		this.edit.setTextColor(Color.BLACK)  ;
		String temp=s.toString();
		if(temp!=null&&!temp.equals(""))
		{
			try {
				double d = Double.parseDouble(temp);
				if(d>Integer.parseInt(this.max))
				{
					this.edit.setTextColor(Color.RED)  ;
					Toast.makeText(ClientApplication.getAppInstance(), "录入的值过大!!!", Toast.LENGTH_SHORT).show();
				}
				
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
		}
	}
	

}
